package com.tomtop.core.model;

import com.tomtop.core._enum.CustomStatus;
import com.tomtop.core._enum.CustomStatus.LogLevel;
import com.tomtop.core.exception.CustomException;

public class ResponseEntity<T>  {
	private int code;
	private String message;
	private String details;
	private LogLevel level;
	private T entity;
	
	public ResponseEntity(CustomException customException) {
		this.code=customException.getCode();
		this.message=customException.getDescribe();
		this.details=customException.getDetails();
		this.level=customException.getLevel();
	}
	public ResponseEntity(T entity,CustomStatus customStatus) {
		this.entity=entity;
		if(customStatus==null)
			customStatus=CustomStatus.OK;
		this.code=customStatus.code();
		this.message=customStatus.message();
		this.level=customStatus.getLevel();
	}
	public ResponseEntity(T entity) {
		this(entity, null);
	}
	public ResponseEntity(CustomStatus customStatus) {
		this(null,customStatus);
	}
	public ResponseEntity() {
		this(null,null);
	}
	
	public int getCode() {
		return code;
	}
	public void setCode(int code) {
		this.code = code;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public String getDetails() {
		return details;
	}
	public void setDetails(String details) {
		this.details = details;
	}
	public T getEntity() {
		return entity;
	}
	public void setEntity(T entity) {
		this.entity = entity;
	}
	public LogLevel getLevel() {
		return level;
	}
	public void setLevel(LogLevel level) {
		this.level = level;
	}
	public static <S> ResponseEntity<S> now(){
		return new ResponseEntity<>();
	}
	public static <S> ResponseEntity<S> now(CustomException customException){
		return new ResponseEntity<>(customException);
	}
	
	public static <S> ResponseEntity<S> now(S entity,CustomStatus customStatus){
		return new ResponseEntity<>(entity, customStatus);
	}
	public static <S> ResponseEntity<S> now(S entity){
		return new ResponseEntity<>(entity);
	}
	public static <S> ResponseEntity<S> now(CustomStatus customStatus){
		return new ResponseEntity<>(customStatus);
	}
}
